use "/Users/jimgolby/Desktop/ZB - Confidence Book/Data/Final Wave 1 Survey/Wave 1 Weighted.dta"

***Defining Variables***
replace q8 =. if q8 > 4

generate q8a = .
replace q8a = 0 if q8 < 5
replace q8a = 1 if q8 < 3

label define CONFIDENCE 0 "Not Confident" 1 "Confidence"
label values q8a CONFIDENCE

generate pid3 =.
replace pid3 = 1 if partyid7 < 4
replace pid3 = 2 if partyid7 == 4
replace pid3 = 3 if partyid7 > 4

label define PARTY 1 "Democrats" 2 "Independents" 3 "Republicans"
label values pid3 PARTY

generate dem = 0 if pid3 < 4
replace dem = 1 if pid3 == 1
generate rep = 0 if pid3 < 4
replace rep = 1 if pid3 == 3
generate ind = 0 if pid3 < 4
replace ind = 1 if pid3 == 2

generate ideo3 =.
replace ideo3 = 1 if ideo < 4
replace ideo3 = 2 if ideo == 4
replace ideo3 = 3 if ideo > 4 & ideo < 8

generate ideo3a = ideo3
replace ideo3a = 4 if ideo == 8

gen lib = 0
replace lib = 1 if ideo3 == 1
gen mod = 0
replace mod = 1 if ideo3 == 2
gen con = 0
replace con = 1 if ideo3 == 3

generate woman = 0
replace woman = 1 if gender == 2
generate male = 0
replace male = 1 if gender == 1

gen vet = veteran if veteran < 98
replace vet = 0 if veteran == 2
replace vet = 0 if veteran2 == 1
replace vet =. if veteran2 == 98

gen activeduty = 0 if veteran < 98
replace activeduty =. if veteran2 == 98
replace activeduty = 1 if veteran2 == 1

generate milvet= 0
replace milvet = 1 if vet == 1
replace milvet = 2 if activeduty == 1

generate post911vet = 0
replace post911vet = 1 if milvet > 0 & vet_date1 < 2001
replace post911vet = 2 if milvet > 0 & vet_date1 > 2000

generate social = 0 if q45 < 98
replace social = 1 if q45 == 1

generate family = 0 if q46 < 98
replace family = 1 if q46 == 1
replace family = . if q46b_dk == 1

generate religion = 0 if relig < 98
replace religion = 1 if relig == 1
replace religion = 2 if relig == 2
replace religion = 3 if relig > 8 & relig < 12
replace religion = 1 if relig == 12

label define RELIGION2 0 "Other" 1 "Christian" 2 "Catholic" 3 "None"
label values religion RELIGION2

generate christian = 0
replace christian = 1 if religion == 1
generate catholic = 0
replace catholic = 1 if religion == 2
generate norelig = 0
replace norelig = 1 if religion == 3

generate white = 0
replace white = 1 if racethnicity == 1
generate black = 0
replace black = 1 if racethnicity == 2
replace black = 1 if racethnicity == 3
generate hispanic = 0
replace hispanic = 1 if racethnicity == 4
generate asian = 0
replace asian = 1 if racethnicity == 6

gen race2 = racethnicity
replace race2 =. if racethnicity == 3
replace race2 =. if racethnicity == 5

label define RACE 1 "White" 2 "Black" 4 "Hispanic" 6 "Asian"
label values race2 racethnicity RACE

generate generation =.
replace generation = 1 if age > 73
replace generation = 2 if age > 54 & age < 74
replace generation = 3 if age > 38 & age < 55
replace generation = 4 if age > 22 & age < 39
replace generation = 5 if age < 23

generate silent = 0
replace silent = 1 if generation == 1
generate boomer = 0
replace boomer = 1 if generation == 2
generate genx = 0
replace genx = 1 if generation == 3
generate milen = 0
replace milen = 1 if generation == 4
generate genz = 0
replace genz = 1 if generation == 5

generate northeast = 0
replace northeast = 1 if region4 == 1
generate midwest = 0
replace midwest = 1 if region4 == 2
generate south = 0
replace south = 1 if region4 == 3 
generate west = 0
replace west = 1 if region4 == 4 

generate city = 0
replace city = 1 if urban3 == 1
generate suburban = 0
replace suburban = 1 if urban3 == 2
generate rural = 0
replace rural = 1 if urban3 == 3

generate unemployed = 0 if employ < 3
replace unemployed = 1 if employ > 2
replace unemployed = 0 if employ == 5

generate income5 =.
replace income5 = 1 if income < 5
replace income5 = 2 if income > 4 & income < 9
replace income5 = 3 if income > 8 & income < 12
replace income5 = 4 if income > 11 & income < 15
replace income5 = 5 if income > 14

gen married =.
replace married = 1 if marital == 1
replace married = 0 if marital > 1

replace q14=. if q14 > 76
replace age=. if age == 286

gen d2 = 0
gen d3 = 0
gen d4 = 0
gen d5 = 0
gen d6 = 0
gen d7 = 0
gen d8 = 0

replace d2 = 1 if dov_assignment_a == 2
replace d3 = 1 if dov_assignment_a == 3
replace d4 = 1 if dov_assignment_a == 4
replace d5 = 1 if dov_assignment_a == 5
replace d6 = 1 if dov_assignment_a == 6
replace d7 = 1 if dov_assignment_a == 7
replace d8 = 1 if dov_assignment_a == 8

gen educ5 = educ4
replace educ5 = 5 if educ > 12 & educ < 15

gen q15a2 = 0 if q15a < 77
replace q15a2 = 1 if q15a < 3
gen q15b2 = 0 if q15b < 77
replace q15b2 = 1 if q15b < 3
gen q15c2 = 0 if q15c < 77
replace q15c2 = 1 if q15c < 3
gen q15d2 = 0 if q15d < 77
replace q15d2 = 1 if q15d < 3
gen q15e2 = 0 if q15e < 77
replace q15e2 = 1 if q15e < 3
gen q15f2 = 0 if q15f < 77
replace q15f2 = 1 if q15f < 3
gen q15g2 = 0 if q15g < 77
replace q15g2 = 1 if q15g < 3

gen q42a2 = 0 if q42a < 77
replace q42a2 = 1 if q42a < 3
gen q42f2 = 0 if q42f < 77
replace q42f2 = 1 if q42f < 3


label define Confidence 0 "Not Confident" 1 "Confident"
label values q8a Confidence

replace q12a =. if q12a > 5
replace q12b =. if q12b > 5
replace q12c =. if q12c > 5
replace q12d =. if q12d > 5
replace q12e =. if q12e > 5
replace q12f =. if q12f > 5
replace q12g =. if q12g > 5
replace q8 =. if q8 > 4

gen q12a2 = 0 if q12a < 77
replace q12a2 = 1 if q12a < 3
gen q12b2 = 0 if q12b < 77
replace q12b2 = 1 if q12b < 3
gen q12c2 = 0 if q12c < 77
replace q12c2 = 1 if q12c < 3
gen q12d2 = 0 if q12d < 77
replace q12d2 = 1 if q12d < 3
gen q12e2 = 0 if q12e < 77
replace q12e2 = 1 if q12e < 3
gen q12f2 = 0 if q12f < 77
replace q12f2 = 1 if q12f < 3
gen q12g2 = 0 if q12g < 77
replace q12g2 = 1 if q12g < 3

recode q12a q12b q12c q12d q12e q12f q12g (1=5)(5=1)(2=4)(4=2)

gen p2 =.
replace p2 = 0 if dov_assignment_a == 1
replace p2 = 1 if dov_assignment_a == 2
gen p3 =.
replace p3 = 0 if dov_assignment_a == 1
replace p3 = 1 if dov_assignment_a == 3 
gen p4 =.
replace p4 = 0 if dov_assignment_a == 1
replace p4 = 1 if dov_assignment_a == 4 
********************

********************
*****Table 6.1*****
tab q16 pid3 if dov_assignment_a == 1 [aweight=weight], column

*****Table 6.2*****
tab q16a pid3 if dov_assignment_a == 1 [aweight=weight], column

*****Table 6.3*****
tab q17 pid3 if dov_assignment_a == 1 [aweight=weight], column

*****Table 6.4*****
tab q18 pid3 if dov_assignment_a == 1 & q18 < 98 [aweight=weight], column

*****Table 6.5*****
tab q12a2 pid3 if dov_assignment_a == 1 [aweight=weight], column
tab q12d2 pid3 if dov_assignment_a == 1 [aweight=weight], column
tab q12g2 pid3 if dov_assignment_a == 1 [aweight=weight], column


*****Figure 6.1*****
mean q8a if dov_assignment_a < 5 [pweight=weight], over(dov_assignment_a)

*****Figure 6.2*****
mean q8a if dov_assignment_a < 5 [pweight=weight], over(pid3 dov_assignment_a)


*****Table 6.8*****
mean q12a2 q12b2 q12c2 q12e2 q12f2 q12g2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)

mean q12a2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)
mean q12b2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)
mean q12c2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)
mean q12e2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)
mean q12f2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)
mean q12g2 if dov_assignment_a < 5 & ind == 0 [pweight=weight], over(pid3 dov_assignment_a)


*****TABLE 6.9*****
*****GOP MIL*****
sem (q12a q12b q12e q12f q12g <- p5) (q8a <- q12a q12b q12e q12f q12g p2) [pweight=weight]
estat teffects

*****DEM MIL*****
sem (q12a q12b q12e q12f q12g <- p7) (q8a <- q12a q12b q12e q12f q12g p3) [pweight=weight]
estat teffects

*****Partisan MIL*****
sem (q12a q12b q12e q12f q12g <- p8) (q8a <- q12a q12b q12e q12f q12g p4) [pweight=weight]
estat teffects


*****Figure 6.5*****
mean q42a2 if dov_assignment_c > 1 & dov_assignment_c < 6 [pweight=weight], over(pid3 dov_assignment_c)

*****Figure 6.6*****
mean q42f2 if dov_assignment_c > 1 & dov_assignment_c < 6 [pweight=weight], over(pid3 dov_assignment_c)

